package com.mutual.assistance.exception.code;

public enum ExceptionCode implements BaseExceptionCode {

    SUCCESS(0, "成功"),
    SYSTEM_BUSY(-1, "系统繁忙~请稍后再试~"),
    SYSTEM_TIMEOUT(-2, "系统维护中~请稍后再试~"),
    PARAM_EX(-3, "参数类型解析异常"),
    SQL_EX(-4, "运行SQL出现异常"),
    NULL_POINT_EX(-5, "空指针异常"),
    ILLE_GALA_ARGUMENT_EX(-6, "无效参数异常"),
    MEDIA_TYPE_EX(-7, "请求类型异常"),
    LOAD_RESOURCES_ERROR(-8, "加载资源出错"),
    BASE_VALID_PARAM(-9, "统一验证参数异常"),
    OPERATION_EX(-10, "操作异常"),
    INVALID_OBJECT(-11, "无效的对象"),
    DATABASE_FIELD_DOES_NOT_EXIST(-12, "无法改变数据库不存在的字段"),
    REPEAT_ADDITION(-13, "已存在，请勿重复添加"),
    FAILED_TO_UPLOAD_IMAGE(-14, "上次文件出错"),
    INVALID_VERIFICATION_CODE(-15, "无效的验证码"),
    THE_USER_IS_NOT_LOGGED_IN_OR_THE_USER_DOES_NOT_EXIST(-16, "该用户未登录或者用户不存在"),
    DISABLED_USER(-17, "用户已被禁用"),
    INSUFFICIENT_POINTS(-18, "用户积分不足"),
    CREDIT_ERROR(-19, "用户积分不能小于0"),

    EMAIL_DOES_NOT_EXIST(-17, "该用户为无效邮箱"),

    REVOKE_FAILED(-18, "只能撤销未经管理员审核发布的任务，如要撤销已发布任务请编辑下架"),

    REPEAT_AUDIT(-19, "该任务已经审核过了，请勿重复审核"),

    RECEIVED_TASK(-20, "不能删除用户已经接收的任务"),
    ROLL_BACK_CREDIT_FALSE(-21, "回滚用户积分失败"),

    TOO_MANY_TASKS(-22, "接收的任务数不能超过3个，请先完成任务再来接收"),
    ANSWERS(-23, "问答互助任务不能单人接收任务"),
    NOT_START(-24, "任务还没有开始"),
    ENDED(-25, "任务已经结束"),
    RECEIVED(-26, "任务已经被其他用户接收"),
    INCORRECT_RECEPTION(-27, "不能自己接收自己的任务"),
    UNSUPPORTED_TASK_TYPE(-28, "不支持的任务类型，只有问答任务才能发布评论。"),
    UNABLE_ADD_COMMENT(-29, "当前任务无法再增加评价，任务已超期或者已完成。"),
    ILLEGAL_SPEECH(-30, "用户发言包含敏感词汇"),
    SUBMITTED_TYPE_INCORRECT(-31, "任务的类型不正确。"),
    SUBMITTED_STATUS_INCORRECT(-32, "任务的状态不正确。"),
    UPDATE_PRE_TASK(-33, "不能更新用户已经接收发布任务的预发布信息。"),
    INVALID_RECIPIENT(-34, "上传任务完成者与数据库记录不一致"),
    TASK_TIME_ERROR(-35, "任务发布时间错误"),

    OK(200, "OK"),
    BAD_REQUEST(400, "错误的请求"),
    UNAUTHORIZED(401, "未经授权"),
    NOT_FOUND(404, "没有找到资源"),
    METHOD_NOT_ALLOWED(405, "不支持当前请求类型"),

    TOO_MANY_REQUESTS(429, "请求超过次数限制"),
    INTERNAL_SERVER_ERROR(500, "内部服务错误"),
    BAD_GATEWAY(502, "网关错误"),
    GATEWAY_TIMEOUT(504, "网关超时"),
    REQUIRED_FILE_PARAM_EX(1001, "请求中必须至少包含一个有效文件"),

    JWT_TOKEN_EXPIRED(40001, "会话超时，请重新登录"),
    JWT_SIGNATURE(40002, "不合法的token，请认真比对 token 的签名"),
    JWT_ILLEGAL_ARGUMENT(40003, "缺少token参数"),
    JWT_GEN_TOKEN_FAIL(40004, "生成token失败"),
    JWT_PARSER_TOKEN_FAIL(40005, "解析token失败"),
    JWT_USER_INVALID(40006, "用户名或密码错误"),
    JWT_USER_ENABLED(40007, "用户已经被禁用！");

    private final int code;
    private String msg;

    ExceptionCode(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }


    public ExceptionCode build(String msg, Object... param) {
        this.msg = String.format(msg, param);
        return this;
    }

    public ExceptionCode param(Object... param) {
        msg = String.format(msg, param);
        return this;
    }
}
